package com.yhy.wxzn.wcs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yhy.wxzn.common.enums.WmsMsgStatusEnums;
import com.yhy.wxzn.wcs.entity.WmsAsyncMsg;
import com.yhy.wxzn.wcs.mapper.WmsAsyncMsgMapper;
import com.yhy.wxzn.wcs.service.IWmsAsyncMsgService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

/**
 * @Description: 异步任务表
 * @Author: jeecg-boot
 * @Date:   2023-11-01
 * @Version: V1.0
 */
@Service

public class WmsAsyncMsgServiceImpl extends ServiceImpl<WmsAsyncMsgMapper, WmsAsyncMsg> implements IWmsAsyncMsgService {

    @Override
    public void genAsyncMsg(String msg, int msgType, String relateCode) {
        //先查询是否已有数据生成
        LambdaQueryWrapper<WmsAsyncMsg> msgQuery = new LambdaQueryWrapper<>();
        msgQuery.eq(WmsAsyncMsg::getMsgType,msgType);
        msgQuery.eq(WmsAsyncMsg::getRelateCode,relateCode);
        msgQuery.eq(WmsAsyncMsg::getMsgStatus,WmsMsgStatusEnums.READY.getValue());
        WmsAsyncMsg message = this.getOne(msgQuery);
        if(ObjectUtils.isEmpty(message)){
            message = new WmsAsyncMsg();
            message.setMsg(msg);
            message.setMsgType(msgType);
            message.setMsgStatus(WmsMsgStatusEnums.READY.getValue());
            message.setRelateCode(relateCode);
            this.save(message);
        }
    }
}
